package com.zzty.txj.util;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EmailUtil {
    private Logger logger = LoggerFactory.getLogger(EmailUtil.class);
    public String sendEmail(String newEmail,String emailContent,String userName) {
        String str="<tr><th>姓名</th><th>日期</th><th>科目</th><th>打卡情况</th><th>最终结果</th></tr>";
        String result = "success";
        logger.info("===initialDelay: send email begin ");
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.163.com"); // 设定smtp服务器
        email.setAuthentication("wenteng_cui@163.com", "teng1234"); // 设定smtp服务器的认证资料信息
        try {
            email.addTo(newEmail, userName); // 设定收件人
            email.setFrom("wenteng_cui@163.com", "自在天原");
            email.setSubject("打卡周报！");
            email.setCharset("UTF-8");
            email.setHtmlMsg("<html><table align='center' border='1' cellspacing='0' cellpadding='3'>" +str+ emailContent + "</table></html>");
            email.send();
        } catch (EmailException e) {
            e.printStackTrace();
        }
        logger.info("===initialDelay: end");
        return result;
    }
}
